﻿namespace Kannon.Util
{
    public static class StringExtensions
    {
        public static int IndexOfAny(this string value, int startIndex, params char[] anyOf)
        {
            return value.IndexOfAny(anyOf, startIndex);
        }

        public static int IndexOfAny(this string value, string anyOf, int startIndex)
        {
            return value.IndexOfAny(startIndex, anyOf.ToCharArray());
        }

        public static bool IsNullOrEmpty(this string value)
        {
            return string.IsNullOrEmpty(value);
        }

        public static string ToLowerCamelCase(this string s)
        {
            return s.Substring(0, 1).ToLowerInvariant() + s.Substring(1);
        }

        public static string SubstringBefore(this string s, string substring)
        {
            var substringOffset = s.IndexOf(substring);

            return substringOffset == -1 ?
                s :
                s.Substring(0, substringOffset);
        }

        public static string SubstringAfter(this string s, string substring)
        {
            var start = s.IndexOf(substring);

            return start == -1 ?
                s :
                s.Substring(start + substring.Length);
        }

        public static string SubstringBetween(this string s, string start, string end)
        {
            return s.SubstringAfter(start).SubstringBefore(end);
        }
    }
}
